package com.zhijian.warehouse.manage.job;


import com.zhijian.warehouse.manage.service.StoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

/**
 * 定时任务任务
 *
 * @Version 1.0.1
 */
@Service
public class TestJob {
    private final static Logger logger = LoggerFactory.getLogger(TestJob.class);
    
    @Autowired
    private StoreService storeService;
    
    /**
     * 刷新期末库存和期初库存 每天 0点5分0秒执行一次判断
     */
    @Scheduled(cron = "${job.test.cron:0 5 0 * * ? }")
    public void flushStore() {
        LocalDate currentDate = LocalDate.now();
        //判断当前时间是否是本月第一天
        if (currentDate.getDayOfMonth() == 1) {
            //刷新库存期初库存 和 库存期末库存置空
            storeService.flushStore();
        }
        //判断当前时间是否是本月最后一天
        else if (currentDate.getDayOfMonth() == currentDate.lengthOfMonth()) {
            storeService.flushStoreEnd();//刷新当前库存到期末库存
        }
    }
}
